﻿using System;
using System.Collections.Generic;
using System.Linq;
using MindMelder.Core;
using MindMelder.Core.DataInterfaces;
using NHibernate;
using NHibernate.Criterion;
using SharpArch.Data.NHibernate;

namespace MindMelder.Data
{
	public class UserRepository : NHibernateRepositoryWithTypedId<User, string>, IUserRepository
	{
		public List<User> FindUsersWithSkillsIn(string skill)
		{
			ICriteria criteria = Session.CreateCriteria(typeof(User))
				.CreateCriteria("Skills")
				.Add(Expression.Eq("Name", skill));
			return criteria.List<User>() as List<User>;
		}

		public User Get(int id)
		{
			ICriteria criteria = Session.CreateCriteria(typeof(User))
				.Add(Expression.Eq("Id", id));
			return criteria.List<User>().FirstOrDefault();
		}

		public User GetByOpenId(string openid)
		{
			ICriteria criteria = Session.CreateCriteria(typeof (User))
				.Add(Expression.Eq("OpenId", openid));
			return criteria.List<User>().FirstOrDefault();
		}
	}
}
